package com.hoongs.v1.service;

import java.awt.*;
import java.awt.image.BufferedImage;

public class CodeTest {
    /**
     * 颜色
     */

    private void newconvertToBlack(BufferedImage image) {
        //处理杂色
//        BufferedImage result = handleColor(image);
//        BufferedImage bm2 = MyUtils.bfuShi(result);
//        BufferedImage finalmap = handleColor(bm2);
//        System.out.println(result);
    }

    //颜色处理
    public static String handleColor(BufferedImage smallImg) {
        String color = "";

        int width = smallImg.getWidth();
        int height = smallImg.getHeight();
        int red = 0;
        int green = 0;
        int yellow = 0;

        for (int y = 0; y < width - 1; y++) {
            for (int x = 0; x < height - 1; x++) {
                int pixel = smallImg.getRGB(y, x);
                int r = (pixel & 0xff0000) >> 16;
                int g = (pixel & 0xff00) >> 8;
                int b = (pixel & 0xff);
                if (r > 200 && g < 180 && b < 180) {
                    if (g > 130) {
                        yellow = yellow + 1;
                    } else {
                        red = red + 1;
                    }
                } else if (r < 160 && g > 170 && b < g) {
                    green = green + 1;
                }
            }
        }

        if (green > red && green > yellow) {
            color = "绿色";
        } else if (red > green && red > yellow) {
            color = "红色";
        } else if (yellow > red && yellow > green) {
            color = "黄色";
        } else {
            color = "分析失败";
        }
        System.out.println("绿：" + green + "，黄：" + yellow + "，红：" + red);

        return color;
    }

}
